//
//  XHVisitor.m
//  围脖
//
//  Created by 魏兴浩 on 15/12/12.
//  Copyright © 2015年 wxh. All rights reserved.
//

#import "XHVisitor.h"
@interface XHVisitor()
//转轮
@property (nonatomic,strong)UIImageView *iconView;
//房子
@property (nonatomic,strong)UIImageView *homeView;
//消息
@property (nonatomic,strong)UILabel *messageLabel;
//注册按钮
@property (nonatomic,strong)UIButton *registerLabel;
//登录登录
@property (nonatomic,strong)UIButton *loginLabel;
//遮盖视图
@property (nonatomic,strong)UIImageView *coverView;
@end

@implementation XHVisitor
-(instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self prepareUI];
    }
    return self;
}
//准备UI
-(void)prepareUI{
    //添加控件
    [self addSubview:self.iconView];
    [self addSubview:self.coverView];
    [self addSubview:self.homeView];
    [self addSubview:self.messageLabel];
    [self addSubview:self.registerLabel];
    [self addSubview:self.loginLabel];

    
    //添加约束
    self.iconView.translatesAutoresizingMaskIntoConstraints = NO;
    self.homeView.translatesAutoresizingMaskIntoConstraints = NO;
    self.messageLabel.translatesAutoresizingMaskIntoConstraints = NO;
    self.registerLabel.translatesAutoresizingMaskIntoConstraints = NO;
    self.loginLabel.translatesAutoresizingMaskIntoConstraints = NO;
    self.coverView.translatesAutoresizingMaskIntoConstraints = NO;
    
    
    //添加转轮
    [self addConstraint: [NSLayoutConstraint constraintWithItem:self.iconView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX  multiplier:1 constant:0]];
    //添加转轮的Y自定义约束
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.iconView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY  multiplier:1 constant:-15]];
    
    //添加遮盖视图
    [self addConstraint: [NSLayoutConstraint constraintWithItem:self.coverView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeWidth  multiplier:1 constant:0]];
    //
   [self addConstraint: [NSLayoutConstraint constraintWithItem:self.coverView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop  multiplier:1 constant:0]];
    
    [self addConstraint: [NSLayoutConstraint constraintWithItem:self.coverView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.registerLabel attribute:NSLayoutAttributeBottom multiplier:1 constant:50]];
    
    //添加房子
    [self addConstraint: [NSLayoutConstraint constraintWithItem:self.homeView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.iconView attribute:NSLayoutAttributeCenterX  multiplier:1 constant:0]];
    //添加房子的Y自定义约束
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.homeView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.iconView attribute:NSLayoutAttributeCenterY  multiplier:1 constant:0]];
    

    //添加消息
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.messageLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.iconView attribute:NSLayoutAttributeCenterX  multiplier:1 constant:0]];
    //添加消息的Y的自定义约束
   [self addConstraint: [NSLayoutConstraint constraintWithItem:self.messageLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.iconView attribute:NSLayoutAttributeBottom  multiplier:1 constant:16]];
    //添加消息的宽高的自定义约束
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.messageLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute  multiplier:1 constant:225]];
    
    
    //约束注册按钮左
    [self addConstraint: [NSLayoutConstraint constraintWithItem:self.registerLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.messageLabel attribute:NSLayoutAttributeLeft  multiplier:1 constant:1]];
   [self addConstraint: [NSLayoutConstraint constraintWithItem:self.registerLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.messageLabel attribute:NSLayoutAttributeBottom  multiplier:1 constant:16]];
    //注册的宽高
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.registerLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:90]];
    [self addConstraint: [NSLayoutConstraint constraintWithItem:self.registerLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute  multiplier:1 constant:35]];
    
    //约束登录按钮左
    [self addConstraint: [NSLayoutConstraint constraintWithItem:self.loginLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.messageLabel attribute:NSLayoutAttributeRight multiplier:1 constant:1]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.loginLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.messageLabel attribute:NSLayoutAttributeBottom  multiplier:1 constant:16]];
    //登录的宽高
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.loginLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:90]];
    [self addConstraint: [NSLayoutConstraint constraintWithItem:self.loginLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute  multiplier:1 constant:35]];
    

    
    
}
#pragma mark -访客视图页面内容
-(void)setVisitorView:(NSString *)imageName andMessage:(NSString *)message{
    self.iconView.image = [UIImage imageNamed:imageName];
    self.messageLabel.text = message;
    //隐藏遮盖视图
    self.coverView.hidden = YES;
    //隐藏房子图片
    self.homeView.hidden = YES;
}
#pragma mark -转轮动画
-(void)IcomViewRotationAnimation{
    //使用核心动画
    CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    //旋转弧度
    basicAnimation.toValue = @(2 * M_PI);
    //设置旋转一圈的时间
    basicAnimation.duration = 10;
    //设置旋转次数为最大
    basicAnimation.repeatCount = MAXFLOAT;
    //设置次属性防止离开页面后停止动画
    basicAnimation.removedOnCompletion = NO;
    //为控件添加动画
    [self.iconView.layer addAnimation:basicAnimation forKey:@"rotation"];
}
#pragma mark -登录按钮点击事件
-(void)loginLabelBtnClick{
//    NSLog(@"点击登录按钮");
    [self.deleaget vistorLoginClick];
}
#pragma mark -懒加载
//转轮
-(UIImageView *)iconView{
    if (!_iconView) {
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    }
    return _iconView;
}
//房子
-(UIImageView *)homeView{
    if (!_homeView) {
        _homeView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    }
    return _homeView;
}
//消息
-(UILabel *)messageLabel{
    if (!_messageLabel) {
        _messageLabel = [[UILabel alloc]init];
        //设置消息文本
        _messageLabel.text = @"关注一些人,看看有没有什么惊喜";
        //设置消息文本颜色
        _messageLabel.textColor = [UIColor lightGrayColor];
        //设置消息文本字体大小
        _messageLabel.font = [UIFont systemFontOfSize:15];
        //设置消息文本自动换行
        _messageLabel.numberOfLines = 0;
        [_messageLabel sizeToFit];
    }
    return _messageLabel;
}
//注册按钮
-(UIButton *)registerLabel{
    if (!_registerLabel) {
        _registerLabel = [[UIButton alloc]init];
        [_registerLabel setTitle:@"注册" forState:UIControlStateNormal];
        [_registerLabel setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [_registerLabel setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
    }
    return _registerLabel;
}
//登录按钮
-(UIButton *)loginLabel{
    if (!_loginLabel) {
        _loginLabel = [[UIButton alloc]init];
        [_loginLabel setTitle:@"登录" forState:UIControlStateNormal];
        [_loginLabel setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [_loginLabel setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
        //添加点击事件
        [_loginLabel addTarget:self action:@selector(loginLabelBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _loginLabel;
}
//遮盖视图
-(UIImageView *)coverView{
    if (!_coverView) {
        _coverView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
    }
    return _coverView;
}
@end
